<script language="javascript" type="text/javascript">

    function getCategoryType(obj){
        $.ajax({
            url: AJAX_PROCESS_URL+'getCategoryType',
            type: 'POST',
            data: "type=" + obj.value,
            error: function(){
                alert('Connection error!');
            },
            success: function(data){
                $("select[name=cat_id]").html(data);
            }
        });
    }
    function getGeo(obj,forObj){
        if(obj.value>0){
            $.ajax({
                url: AJAX_PROCESS_URL+'getDistrict',
                type: 'POST',
                data: "city=" + obj.value,
                error: function(){
                    alert('Error!');
                },
                success: function(data){
                    if(forObj=='city'){
                        $("select[name=geo_id[0]]").html(data);
                        $("select[name=geo_id[1]]").html('<option value="0">[Chọn]...</option>');
                    }else if(forObj=='district'){
                        $("select[name=district]").html(data);
                    }

                }
            });
        }else{
            $("select[name=geo_id[1]]").html('<option value="0">[Chọn]...</option>');
        }
    }
    function search (){
        $('#frmSearch').submit();
    }
</script>


<div class="left_content_SBDS">

    <div class="left_box">
        <div class="title_search" style="background: url('/images/title_search.gif') no-repeat;"><span></span></div>
        <div class="box_body">
            <form action="<?php echo get_link('property');?>/" id="frmSearch" method="get">
                <div class="linesearch">
                    <ul>
                        <li>
                            <div class="linesearh_left">[Loại hình]:</div>
                            <div class="linesearh_right">
                                <select name="type" onchange="getCategoryType(this);">
                                    <option value="0">[Chọn loại tin]</option>
                                    <?php
                                    if($_REQUEST['type']==2) {
                                        echo '<option value="1">[Cần bán]</option>';
                                        echo '<option selected="selected" value="2">[Cho thuê]</option>';
                                    }elseif($_REQUEST['type']==1) {

                                        echo '<option selected="selected" value="1">[Cần bán]</option>';
                                        echo '<option value="2">[Cho thuê]</option>';
                                    }else {
                                        echo '<option value="1">[Cần bán]</option>';
                                        echo '<option value="2">[Cho thuê]</option>';
                                    }
                                    ?>
                                </select>
                            </div>
                        </li>
                        <li>
                            <div class="linesearh_left">[Danh mục]:</div>
                            <div class="linesearh_right">
                                <select name="cat_id">
                                    <?php
                                    if(intval($_REQUEST['type'])==0) {
                                        $type = 1;
                                    }else {
                                        $type = intval($_REQUEST['type']);
                                    }
                                    $arrCatId = listPropertyCategoryByParent($type);
                                    echo '<option value="0">[Chọn loại địa ốc]</option>';
                                    for($i=0;$i<count($arrCatId);$i++) {
                                        echo '<option '.setSelectedBoxValue($_REQUEST['cat_id'], $arrCatId[$i]['cat_id']).' value="'.$arrCatId[$i]['cat_id'].'">'.$arrCatId[$i]['cat_title'].'</option>';
                                    }

                                    ?>
                                </select>
                            </div>
                        </li>
                        <li><div class="linesearh_left">[Tỉnh/TP]:</div>
                            <div class="linesearh_right">
                                <select name="city" onchange="getGeo(this,'district')">
                                    <option value="0">[Tỉnh/Thành phố]</option>
                                    <?php
                                    $rsCity = getAllCity();
                                    while ($row = $db->fetch_array($rsCity)) {
                                        if($_REQUEST['city']==$row['geo_id']) {
                                            echo '<option selected="selected" value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                        }else {
                                            echo '<option value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </li>
                        <li><div class="linesearh_left">[Quận huyện]:</div>
                            <div class="linesearh_right">
                                <select name="district">
                                    <option value="0">[Quận/Huyện]</option>
                                    <?php
                                    if(isset ($_REQUEST['city']) && intval($_REQUEST['city'])>0) {
                                        $rsDistrict = getDistrictByCityId(intval($_REQUEST['city']));
                                        while ($row = $db->fetch_array($rsDistrict)) {
                                            if($_REQUEST['district']==$row['geo_id']) {
                                                echo '<option selected="selected" value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                            }else {
                                                echo '<option value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                            }
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </li>
                        <li><div class="linesearh_left">[Giá (VNĐ)]:</div>
                            <div class="linesearh_right">
                                <select name="price_home">
                                    <option value="0">[Chọn giá]</option>
                                    <option <?php echo setSelectedBoxValue($_REQUEST['price_home'], 'p500');?> value="p500"><500 [Triệu]</option>
                                    <option <?php echo setSelectedBoxValue($_REQUEST['price_home'], 'p500-1');?> value="p500-1">500 [Triệu] - 1 [Tỷ]</option>
                                    <option <?php echo setSelectedBoxValue($_REQUEST['price_home'], 'p1-3');?> value="p1-3">1 [Tỷ] - 3 [Tỷ]</option>
                                    <option <?php echo setSelectedBoxValue($_REQUEST['price_home'], 'p3-5');?> value="p3-5">3 [Tỷ] - 5 [Tỷ]</option>
                                    <option <?php echo setSelectedBoxValue($_REQUEST['price_home'], 'p5');?> value="p5">[Lớn hơn] 5 [Tỷ]</option>
                                    <option <?php echo setSelectedBoxValue($_REQUEST['price_home'], 'noPrice');?> value="noPrice">[Chưa có giá]</option>
                                </select>
                            </div>
                        </li>
                        <li><div class="linesearh_left">[Diện tích]:</div>

                            <div class="linesearh_right"><select name="area" >
                                    <option value="0">Chọn diện tích</option>
                                    <option <?php setSelectedBoxValue($_REQUEST['area'], 'a50');?> value="a50">< 50m2</option>
                                    <option <?php setSelectedBoxValue($_REQUEST['area'], 'a50-100');?> value="a50-100">50m2 -> 100m2</option>
                                    <option <?php setSelectedBoxValue($_REQUEST['area'], 'a101-200');?> value="a101-200">101m2 -> 200m2</option>
                                    <option <?php setSelectedBoxValue($_REQUEST['area'], 'a201');?> value="a201">> 200m2</option>
                                </select></div>

                        </li>
                        <li><div class="linesearh_left">[Hướng]:</div>
                            <div class="linesearh_right">
                                <select name="direction" style="width:99%;">
                                    <?php
                                    foreach ($CONFIG['direction'] as $key => $value) {
                                        if(isset($_REQUEST['direction']) && $_REQUEST['direction']==$key) {
                                            echo '<option selected="selected" value="'.$key.'">'.$value.'</option>';
                                        }else {
                                            echo '<option value="'.$key.'">'.$value.'</option>';
                                        }
                                    }
                                    ?>
                                </select>
                            </div>
                        </li>
                        <li><div class="linesearh_left">[Từ khóa]:</div>
                            <div class="linesearh_right"><input type="text" name="keyword" value="<?php if(isset($_REQUEST['keyword'])) {
                                    echo $_REQUEST['keyword'];
                                }else {
                                    echo '[Tìm kiếm BĐS]';
                                                                }?>" onkeydown="if (event.keyCode == 13){search();return false;}" onclick="if(this.value=='[Tìm kiếm BĐS]'){this.value=''}" onblur="if(this.value=='' || this.value==' '){this.value='[Tìm kiếm BĐS]'}" style="width:95%;" />
                            </div>
                        </li>

                    </ul>
                    <div onclick="$('#frmSearch').submit();" class="btn_search" style="background-image:url('/images/icon_search.gif');"></div>
                </div>
            </form>
        </div>
        <div class="box_bottom"><span></span></div>

        <div class="title_dm" style="background: url('/images/title_danhmuc.gif') no-repeat;"><span></span></div>
        <div class="box_body">
            <?php
            $catId = getCatIdByPropertyTitleLink($param[1]);
            $arrCatLeft = listAllPropertyCategoryLeft();
            for($i=0;$i<count($arrCatLeft);$i++) {
                if(($param[1]==$arrCatLeft[$i]['cat_link'] || $catId == $arrCatLeft[$i]['cat_id'] || $param[1]=='') && $i==0 ) {
                    ?>
            <div id="slidetop1"><a class="current" href="<?php echo get_link("property","cat",$arrCatLeft[$i]['cat_link']);?>" title="<?echo $arrCatLeft[$i]['cat_title'];?>"><?echo $arrCatLeft[$i]['cat_title'];?></a></div>
                    <?php
                }elseif($param[1]==$arrCatLeft[$i]['cat_link'] && $i!=0 ) {
                    ?>
            <div id="slidetop1"><a class="current" href="<?php echo get_link("property","cat",$arrCatLeft[$i]['cat_link']);?>" title="<?echo $arrCatLeft[$i]['cat_title'];?>"><?echo $arrCatLeft[$i]['cat_title'];?></a></div>
                    <?php
                }else {
                    ?>
            <div id="slidetop1"><a href="<?php echo get_link("property","cat",$arrCatLeft[$i]['cat_link']);?>" title="<?echo $arrCatLeft[$i]['cat_title'];?>"><?echo $arrCatLeft[$i]['cat_title'];?></a></div>
                    <?php
                }
                $arrCatLeft1 = listAllPropertyCategoryLeft($arrCatLeft[$i]['cat_id']);
                if(count($arrCatLeft1)>0) {
                    ?>
            <div id="subslide1">
                <ul>
                            <?php
                            for($i1=0;$i1<count($arrCatLeft1);$i1++) {
                                if($i1==count($arrCatLeft1)-1) {
                                    if($param[1]==$arrCatLeft1[$i1]['cat_link'] || $catId == $arrCatLeft1[$i1]['cat_id']) {
                                        ?>
                    <li class="slideend"><a class="activesub" href="<?php echo get_link("property","cat",$arrCatLeft1[$i1]['cat_link']);?>" title="<?echo $arrCatLeft1[$i1]['cat_title'];?>"><?echo $arrCatLeft1[$i1]['cat_title'];?></a></li>
                                        <?php
                                    }else {
                                        ?>
                    <li class="slideend"><a href="<?php echo get_link("property","cat",$arrCatLeft1[$i1]['cat_link']);?>" title="<?echo $arrCatLeft1[$i1]['cat_title'];?>"><?echo $arrCatLeft1[$i1]['cat_title'];?></a></li>
                                        <?php
                                    }
                                    ?>
                                    <?php
                                }else {
                                    if($param[1]==$arrCatLeft1[$i1]['cat_link'] || $catId == $arrCatLeft1[$i1]['cat_id']) {
                                        ?>
                    <li><a class="activesub" href="<?php echo get_link("property","cat",$arrCatLeft1[$i1]['cat_link']);?>" title="<?echo $arrCatLeft1[$i1]['cat_title'];?>"><?echo $arrCatLeft1[$i1]['cat_title'];?></a></li>
                                        <?php
                                    }else {
                                        ?>
                    <li><a href="<?php echo get_link("property","cat",$arrCatLeft1[$i1]['cat_link']);?>" title="<?echo $arrCatLeft1[$i1]['cat_title'];?>"><?echo $arrCatLeft1[$i1]['cat_title'];?></a></li>
                                        <?php
                                    }
                                    ?>
                                    <?php
                                }
                            }
                            ?>
                </ul>
            </div>
                    <?php
                }
            }
            ?>
        </div>
        <div class="box_bottom"><span></span></div>

        <?php  $rsAdv = getAdvClient('property', 'left', 5);

        if($db->num_rows($rsAdv)>0) {
            ?>
        <div style="float:left;width:100%">
            <div class="folder" >
                <div class="folder-title-new00" >
                    <div class="square00"></div>
                    <div style="margin-top: 7px;float: left;color: #000">[Quảng cáo]</div>
                </div>
                <div class="folder-body00" >
                        <?php
                        while ($row = $db->fetch_array($rsAdv)) {
                            ?>
                    <div style="margin-bottom: 2px;">
                        <a href="<?php echo $row['link'];?>"><img alt="" src="<?php echo $row['filename'];?>" width="188px;" /></a>
                    </div>
                            <?php }?>
                </div>
                <div class="folder-bottom00">
                    <div class="square-bottom00"></div>
                </div>
            </div>
        </div>
            <?php } ?>

    </div>
</div>